<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : userTable.xsl
    Created on : March 25, 2013, 2:37 PM
    Author     : Thinh
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:u="http://xml.netbeans.org/schema/"
        xmlns:p="http://xml.netbeans.org/schema/profile" version="1.0">
    <xsl:output method="html" indent="yes"/>

    <xsl:param name="fieldToSort" />
    <xsl:param name="sortCondition" />
    <xsl:template match="/">
        <div id="userTable">
            <table class="data display datatable" id="tblUser">
                <thead>
                    <tr>
                        <td id="tdId" class="sorting_none" rowspan="1" colspan="1" style="width : 23px">Id</td>
                        <td id="tdUsername" onclick="sort('username', 'tdUsername')" class="sorting" rowspan="1" colspan="1" style="width: 165px">Username</td>
                        <td id="tdFullName"  class="sorting_none" rowspan="1" colspan="1" stype="width: 265px">Full name</td>
                        <td id="tdIsDeleted" class="sorting_none" rowspan="1" colspan="1" stype="width: 265px">Is Deleted</td>
                        <td id="tdAddress" class="sorting_none" rowspan="1" colspan="1" style="width: 179px">Address</td>
                        <td class="sorting_none" rowspan="1" colspan="1"></td>
                        <td class="sorting_none" rowspan="1" colspan="1"></td>
                    </tr>
                </thead>
                <tbody>`
                    <xsl:for-each  select="u:users/u:user">
<!--                    <xsl:sort select="$fieldToSort" order="{$sortCondition}"/>-->
                        <xsl:sort select="@*[name()=$fieldToSort] | *[name()=$fieldToSort]" data-type="text" order="{$sortCondition}"/>
                        <tr class="odd">
                            <td>
                                <a class="close" id="close" href="#close"></a>
                                <xsl:value-of select="position()"/>
                            </td>
                            <td id="username">
                                <xsl:value-of select="u:username"/>
                            </td>
                            <td id="fullname">
                                <xsl:value-of select="u:profile/p:firstname"/>
                                <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]>
                                </xsl:text>
                                <xsl:value-of select="u:profile/p:lastname"/>
                            </td>
                            <td id="isDeleted">
                                <xsl:if test="u:isDeleted = 'false'">
                                    <input disabled="disabled" id="isDeleted"  type="checkbox" name="deleted" value="false"/>
                                </xsl:if>
                                <xsl:if test="u:isDeleted = 'true'">
                                    <input disabled="disabled" id="isDeleted" checked="checked" type="checkbox" name="deleted" value="true"/>
                                </xsl:if>
                            </td>
                            <td id="address">
                                <xsl:value-of select="u:profile/p:address"/>
                            </td>
                            <td>
                                <form id="updateUserForm_{position()}" action="" method="POST"  onsubmit="loadUserXMlFile({position()});  return false;">
                                    <a href="#login_form{@id}" style="text-decoration:none">View Profile</a>
                                    <a href="#x" class="overlay" id="login_form{@id}"></a>
                                    <div id= "user_{position()}" class="popup">
                                        <input type="hidden" name="id" value="{@id}" />
                                        <h2>View
                                            <xsl:value-of select="username"/>'s Profile
                                        </h2>
                                        <div>
                                            <label for="username"> Username: </label>
                                            <input title="6 to 30 characters" type="text" name="username" disabled="true" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:username'/>
                                                </xsl:attribute>
                                            </input>
                                        </div>
                                        <div>
                                            <label for="firstname"> Firstname(*): </label>
                                            <input title="6 to 20 characters" type="text"  name="firstname" disabled="true" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:profile/p:firstname'/>
                                                </xsl:attribute>
                                                <xsl:attribute name="pattern">
                                                    <xsl:text>.{6,20}</xsl:text>
                                                </xsl:attribute>
                                            </input>
                                        </div>
                                        <div>
                                            <label for="lastname"> Lastname(*): </label>
                                            <input title="6 to 20 characters" type="text" name="lastname" disabled="true" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:profile/p:lastname'/>
                                                </xsl:attribute>
                                                <xsl:attribute name="pattern">
                                                    <xsl:text>.{6,20}</xsl:text>
                                                </xsl:attribute>
                                            </input>
                                        </div>
                                        <div>
                                            <label for="address"> Address(*): </label>
                                            <input type="text" name="address" title="Not more than 100 characters!" disabled="true" maxlength="100" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:profile/p:address'/>
                                                </xsl:attribute>
                                            </input>
                                        </div>
                                        <div>
                                            <label for="phoneNumber"> Phone number(*): </label>
                                            <input  title="Only number please!" name="phoneNumber" type="tel" disabled="true" maxlength="13" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:profile/p:phoneNumber'/>
                                                </xsl:attribute>
                                                <xsl:attribute name="pattern">
                                                    <xsl:text>[0-9]{6,20}</xsl:text>
                                                </xsl:attribute>
                                            </input>
                                        </div>
                                        <div>
                                            <label for="email"> Email(*): </label>
                                            <input title="Please fill out your correct email" name="email" disabled="true" type="email" maxlength="50" required="required">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select='u:profile/p:email'/>
                                                </xsl:attribute>
                                            </input>
                                        </div>
<!--                                        <input type="submit"  id="btnUpdateUser" onclick="" value="Update">
                                        <a class="button" href="#close" onclick="loadUserXMlFile({position()})">Update</a>
                                        </input>-->
                                        <a class="close" id="close" href="#"></a>
                                    </div>
                                </form>
                            </td>
                            <td>
                                <xsl:if test="u:isDeleted = 'false'">
                                    <a href="#" id="{@id}_deleted" onclick="deleteUser({@id}, {position()})" style="text-decoration:none">Delete</a>
                                </xsl:if>
                                <xsl:if test="u:isDeleted = 'true'">
                                    <a href="#" id="{@id}_deleted" onclick="deleteUser({@id}, {position()})" style="text-decoration:none">UnDelete</a>
                                </xsl:if>
                            </td>
                        </tr>
                    </xsl:for-each>
                </tbody>
            </table>
        </div>
    </xsl:template>
</xsl:stylesheet>
